package com.sample.springbatch.job.sample.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.LinkedList;

/**
 * Created by zwg on 2017/11/9.
 */
@Service
public class SplitFlowStepService {

    public static final Logger logger = LoggerFactory.getLogger(SplitFlowStepService.class);

    public static LinkedList<Integer> queue = new LinkedList<>();


    public synchronized boolean cleanQueue(){
        if(queue.size()>0){
            queue.clear();
        }
        logger.info("===== clean queue.size:"+queue.size());
        return true;
    }

    public boolean getPageData(int startPage, int endPage){
        for (int i = startPage; i <= endPage; i++) {
            synchronized ((Integer)startPage){
                queue.add(i);
                logger.info("add queue:"+i);
                /*try {
                    Thread.sleep(100L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }*/
            }
        }
        return true;
    }

    public boolean readQueue(){
        for (Integer i: queue) {
            //System.out.println("======"+i);
        }
        logger.info("===== read queue.size:"+queue.size());
        return true;
    }

}
